package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Trump
 * @Date: 2025/8/17 18:51
 * @Description:
 **/
@Api(tags = "商品技术属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseManageController {
@Autowired
    ManageService manageService;

    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> category1List= manageService.getCategory1();
        return Result.ok(category1List);
    }


    @GetMapping("/getCategory2/{id}")
    public Result getCategory2(@PathVariable(name = "id") Integer id){
        List<BaseCategory2> category2List= manageService.getCategory2(id);
        return Result.ok(category2List);
    }

    @GetMapping("/getCategory3/{id}")
    public Result getCategory3(@PathVariable(name = "id") Integer id){
        List<BaseCategory3> category3List= manageService.getCategory3(id);
        return Result.ok(category3List);
    }
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable("category1Id") Long category1Id,
                               @PathVariable("category2Id") Long category2Id,
                               @PathVariable("category3Id") Long category3Id){

        List<BaseAttrInfo> attrInfoList=  manageService.attrInfoList(category1Id,category2Id,category3Id);

        return Result.ok(attrInfoList);
    }


    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        manageService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId){
        BaseAttrInfo baseAttrInfo= manageService.getAttrInfo(attrId);
        List<BaseAttrValue> attrValueList = baseAttrInfo.getAttrValueList();
        return Result.ok(attrValueList);
    }



}
